﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace Core
{
    public class TextWriterTraceListenerWithTime : TextWriterTraceListener
    {
        public TextWriterTraceListenerWithTime()
            : base()
        {
        }

        public TextWriterTraceListenerWithTime(Stream stream)
            : base(stream)
        {
        }

        public TextWriterTraceListenerWithTime(string path)
            : base(path)
        {
        }

        public TextWriterTraceListenerWithTime(TextWriter writer)
            : base(writer)
        {
        }

        public TextWriterTraceListenerWithTime(Stream stream, string name)
            : base(stream, name)
        {
        }

        public TextWriterTraceListenerWithTime(string path, string name)
            : base(path, name)
        {
        }

        public TextWriterTraceListenerWithTime(TextWriter writer, string name)
            : base(writer, name)
        {
        }

        public override void WriteLine(string message)
        {
            WriteLine(message, string.Empty);
        }

        public override void WriteLine(string message, string category)
        {
            TraceEventCache e = new TraceEventCache();
            
            base.Write(e.DateTime.ToString());
            base.Write(" ");          
            
            if (category != string.Empty)
            {
                base.Write((category + "                    ").Substring(0, 20));
                base.Write(": ");
            }
            //base.WriteLine(message+" call:"+e.Callstack+" LOS:"+e.LogicalOperationStack);
            base.WriteLine(message);
        }
        
        public void WriteLineIf(bool condition, string message, string category)
        {
            if (condition)
            {
                WriteLine(message, category);
            }
        }
    }   
}
